/**
*  \file genesis.c
*
*  \brief
*
*  \author Michael J. Hohmann  <michael.hohmann@linde-mh.de>
*
*
*/

/*===============================================[ private includes  ]================================================*/
#include "genesis.h"
#include "../hardware/hardware.h"
#include "../sched/sched.h"
#include "../assertor/assertor.h"
#include "../can/can.h"
#include "../nvram/nvram.h"
#include "../app/app.h"
#include "../seppuku/seppuku.h"
#include "../pal/pal_intrinsic.h"
#include "../random/random.h"
#include "../systime/systime.h"
#include "../cancom/cancom.h"
#include "../mcu/mcu.h"
#include "../systime/systime.h"
#include "../paragen/paragen.h"
#include "../parameter/parameter.h"
#include "../timerecorder/timerecorder.h"
#include "../deaddrop/deaddrop.h"
#include "../pal/pal_intrinsic.h"
#include "../term/term.h"
#include "../supervisor/supervisor.h"
#include "../bdi/bdi.h"
/*===============================================[ private defines   ]================================================*/

/*===============================================[ private datatypes ]================================================*/

/*===============================================[ private variables ]================================================*/



/*===============================================[ private functions ]================================================*/

/*===============================================[ inline functions  ]================================================*/

STATIC_INLINE RC mux_rc( BO selector, RC a, RC b )
{
   if( selector )
   {
      return a;
   }
   return b;
}

/*===============================================[ public functions  ]================================================*/
RC genesis_initialize( void )
{
   BO rv = FALSE;

   rv = rv || hardware_initialize();

   mcu_set_output(mcu_output_TLF_MPS_CON, 0x01);
   
   rv = rv || sched_initialize();

   rv = rv || can_initialize();

   rv = rv || cancom_initialize();
   
   rv = rv || nvram_initialize();

   rv = rv || systime_initialize();

   rv = rv || parameter_initialize();

   rv = rv || term_initialize();

   rv = rv || bdi_init();   

   rv = rv || app_initialize();

   rv = rv || random_construct( NIL, timerecoder_get(timerecoder_channel_component_work_time), mcu_high_resolution_counter );

   rv = rv || seppuku_initialize( sched_get_slice_10ms(), pal_intrinsic_reset, &deaddrop_p->reset_reason );

   rv = rv || mcu_initialize();
   
   rv = rv || hardware_initialize_post();

   return mux_rc( rv, RC_ERROR, RC_SUCCESS );
}


/*===============================================[ private functions ]================================================*/


/***********************************************************************************************************************
*                             Copyright 2018 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
